﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
using System.Collections

namespace translateCTPTD
{
    class Program
    {
        static void Main(string[] args)
        {
            string traderHFile = @"C:\CTP_CSHARP\CTP_V636_20141230_win32\ThostFtdcTraderApi.h";
            string outputAddr = @"D:\CSCTPTD.txt";

            //批量处理API函数
            StreamReader objReader = new StreamReader(traderHFile);
            ArrayList lines = new ArrayList();
            string sLine = "";
            bool apiFlag = false;
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null && sLine.Contains("class TRADER_API_EXPORT CThostFtdcTraderApi"))
                {
                    //找到关键字后进入api部分,主要是替换virtual int *** =0 纯虚函数的重复性部分
                    apiFlag = true;
                }
                if (!apiFlag) {
                    lines.Add(sLine);
                    continue;
                }
                if (sLine.Contains("virtual") && sLine.Contains("0;")) {
                    //添加API宏
                    sLine = sLine.Replace("virtual","CTPTD_API");
                    //去掉=,0,;添加花括号
                    sLine = sLine.Replace("=","");
                    sLine = sLine.Replace("0","");
                    sLine = sLine.Replace("=","");
                    string line1 = sLine + " {"; //签名句
                    string line2 = sLine;//调用句
                    //去掉, int nRequestID
                     line1 = sLine.Replace(", int nRequestID","");


                }
                lines.Add(sLine);
            }
        }
    }
}
